package com.smartwebx.ha.web.admin.module.screen.area;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.smartwebx.ha.biz.assign.HaAreaManager;
import com.smartwebx.ha.dal.assign.bean.HaArea;
import com.smartwebx.ha.dal.bean.AreaAndGroup;
import com.smartwebx.ha.web.admin.common.HaUserSys;

public class AjaxUserAreaInfo {
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private HaAreaManager haAreaManager;
	@Autowired
	private HttpSession session;
	
	public void execute() throws Exception{
		response.setContentType("application/json;charset=UTF-8");
		
		PrintWriter out=response.getWriter();
		HaUserSys user=(HaUserSys) session.getAttribute("haUser");
		HaArea area=haAreaManager.findOne(2);
		AreaAndGroup areaAndGroup=new AreaAndGroup();
		String[] str=area.getCenterPoint().split(",");
		String longitude=str[0];
		String latitude=str[1];
		areaAndGroup.setLongitude(Double.parseDouble(longitude));
		areaAndGroup.setLatitude(Double.parseDouble(latitude));
		BeanUtils.copyProperties(area,areaAndGroup);
		ObjectMapper mapper= new ObjectMapper();
		mapper.writeValue(out, Lists.newArrayList(areaAndGroup));
	}
	
}
